/* MAKE-VECTOR.asm
 *
 * 
 */

MAKEVECTOR:
  PUSH(FP);
  MOV(FP,SP);
  PUSH(R1);
  PUSH(R2);

  CMP(FPARG(1),2);
  JUMP_EQ(MAKE_VEC_2_PARAM);
  PUSH(0);
  CALL(MAKE_SOB_INTEGER);	// creating new sob integer 0
  DROP(1);
  MOV(R1,R0);		// R1 = pointer to sob integer 0
  JUMP(MAKE_VEC_1_PARAM);
MAKE_VEC_2_PARAM:
  MOV(R1,FPARG(3));
MAKE_VEC_1_PARAM:
  MOV(R2, FPARG(2)); 	// R2 = pointer to sob integer which represent the number of vector length
  MOV(R2, INDD(R2,1));	// R2 = number of vector items (length of vector)
  MOV(R0, R2);			// R0 = number of vector items (for loop purpose)

MAKEVECTOR_LOOP:		//loop to push R0 items of siz
  CMP(R0, IMM(0));
  JUMP_EQ(MAKEVECTOR_EXIT);
  PUSH(R1);			// param for MAKE_SOB_VECTOR - making inititation of each vector item to point to the sob integer 0
  DECR(R0);
  JUMP(MAKEVECTOR_LOOP);
 MAKEVECTOR_EXIT:

  PUSH(R2);			// last param for MAKE_SOB_VECTOR - length
  CALL(MAKE_SOB_VECTOR);	// creating the new vector
  INCR(R2); 			// R1 = number of vector items + 1 = number of params sent to MAKE_SOB_VECTOR
  DROP(R2);

  POP(R2);
  POP(R1);
  POP(FP);
  RETURN;

